//app.js
App({
  data: {
    Url: 'https://zhapp.4hl.cn/api/',
    list:'',
    address:{
      name:'',
      id:''
    },
    display_confirm: "block",
    error: function (msg) {
    wx.showToast({
      title: msg,
      icon: 'none'
    })
    wx.hideLoading();
  }
  },
  navTo: function (e) {
    wx.navigateTo({
      url: e,
    })
  },
  
  getUserInfo: function (e) {
    var that = this;
    console.log(e)
    app.globalData.userInfo = e.detail.userInfo
    this.setData({
      userInfo: e.detail.userInfo,
      hasUserInfo: true,
      logo: false
    })
    wx.login({
      success: function () {
        wx.getUserInfo({
          success: function (res) {
            var simpleUser = res.userInfo;
            console.log(simpleUser.nickName);
          }
        });
      }
    });
    wx.showToast({
      title: '恭喜你登陆成功',
      duration: 2000,
      success: function () {
        if (that.data.userType == 1) {
          wx.redirectTo({
            url: '../index/index'
          })
          this.setData({
            display_confirm: "none",
          })
        } else {
          setTimeout(function () {
            wx.redirectTo({
              url: '../index/index'
            });
          }, 2000)
        }
      }
    })
  },
  uploadimg:function(data){
    var that= this,
    i=data.i ? data.i : 0,//当前上传的哪张图片
    success=data.success ? data.success : 0,//上传成功的个数
    fail=data.fail ? data.fail : 0;//上传失败的个数
    wx.uploadFile({
      url: data.url,
      filePath: data.path[i],
      name: 'file',//这里根据自己的实际情况改
      formData: null,//这里是上传图片时一起上传的数据
      success: (resp) => {
        success++;//图片上传成功，图片上传成功的变量+1
        console.log(resp)
        console.log(i);
        //这里可能有BUG，失败也会执行这里,所以这里应该是后台返回过来的状态码为成功时，这里的success才+1
      },
      fail: (res) => {
        fail++;//图片上传失败，图片上传失败的变量+1
        console.log('fail:' + i + "fail:" + fail);
      },
      complete: () => {
        console.log(i);
        i++;//这个图片执行完上传后，开始上传下一张
        if (i == data.path.length) {   //当图片传完时，停止调用          
          console.log('执行完毕');
          console.log('成功：' + success + " 失败：" + fail);
        } else {//若图片还没有传完，则继续调用函数
          console.log(i);
          data.i = i;
          data.success = success;
          data.fail = fail;
          that.uploadimg(data);
        }
      }
    })
  }
})

// {
          //     "pagePath": "pages/seller/seller",
          //     "text": "名品商家",
          //     "iconPath": "pages/image/r_bar.png",
          //     "selectedIconPath": "pages/image/r_bar_hove.png"
          // },